{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "fb817924",
   "metadata": {},
   "source": [
    "-----\n",
    "* 2022/09/20/week05\n",
    "* Python 课堂笔记"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5a035c58",
   "metadata": {},
   "source": [
    "# 本周内容\n",
    "> 1. 有序的数据结构之列表\n",
    "> 2. 用户输入\n",
    "> 3. 关于格式化文本信息"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ad86c2f9",
   "metadata": {},
   "outputs": [],
   "source": [
    "网三_01_name = \"Marry\"\n",
    "\n",
    "# 思考：如果想一个变量存放一个班的同学的名字，该怎么存\n",
    "# 思考：处理数据会不会比较麻烦？"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "471ed457",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Marry,Alex,Jack,周晓明\n"
     ]
    }
   ],
   "source": [
    "网三_name_list = \"Marry,Alex,Jack,周晓明\"\n",
    "print(网三_name_list)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "84075ce9",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Alex'"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "网三_name_list[6:10]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "7bb38fa5",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "19"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 思考3：我想知道这个名单有多少个人名？\n",
    "len(网三_name_list)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e144ffb6",
   "metadata": {},
   "source": [
    "## 1. 引入列表的概念\n",
    "* Lists might contain items of different types, but usually the items all have the same type\n",
    "> 注释：我们已经学习了数值和字符，list可以放数字和字符，但是通常要么一起放数值，要么一起放字符串。\n",
    "\n",
    "> 总结一些通用的有序数据结构的方法\n",
    ">> 1. 取值：用过索引值去除对应的内容\n",
    ">> 2. 切片：通过索引值区间去除对应的一些内容\n",
    ">> 3. in 可以查看成员对象是否存在\n",
    "\n",
    "> 列表的一些方法"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "a42266ce",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1, 2, 3, 4] <class 'list'>\n"
     ]
    }
   ],
   "source": [
    "a = [1,2,3,4]\n",
    "print(a,type(a))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "29de88a3",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['Marry', 'Alex', 'Jack', '周晓明'] <class 'list'>\n"
     ]
    }
   ],
   "source": [
    "网三_name_list = [ \"Marry\",\"Alex\",\"Jack\",\"周晓明\"]\n",
    "print(网三_name_list,type(网三_name_list))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "ab123cfe",
   "metadata": {},
   "outputs": [
    {
     "ename": "SyntaxError",
     "evalue": "invalid syntax (Temp/ipykernel_8188/2651313051.py, line 2)",
     "output_type": "error",
     "traceback": [
      "\u001b[1;36m  File \u001b[1;32m\"C:\\Users\\wxm\\AppData\\Local\\Temp/ipykernel_8188/2651313051.py\"\u001b[1;36m, line \u001b[1;32m2\u001b[0m\n\u001b[1;33m    * <font color = \"red\">列表的数据本身不做修改\u001b[0m\n\u001b[1;37m      ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m invalid syntax\n"
     ]
    }
   ],
   "source": [
    "### 1.1 列表的运算法则（Operation）\n",
    "* <font color = \"red\">列表的数据本身不做修改"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "84110bae",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Marry'"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 取出 网三_name_list 中第一位同学的名字\n",
    "网三_name_list[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "6a576790",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "4"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 查看网三_name_list 有多少同学\n",
    "len(网三_name_list)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "6a77f2c0",
   "metadata": {},
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name '网三_name_list' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[1;32m~\\AppData\\Local\\Temp/ipykernel_8188/1682096953.py\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[1;32mfor\u001b[0m \u001b[0mi\u001b[0m \u001b[1;32min\u001b[0m \u001b[0m网三_name_list\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m      2\u001b[0m     \u001b[0mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"网三\"\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mi\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;31mNameError\u001b[0m: name '网三_name_list' is not defined"
     ]
    }
   ],
   "source": [
    "for i in 网三_name_list:\n",
    "    print(\"网三\",i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "282ff7cb",
   "metadata": {},
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name '网三_name_list' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[1;32m~\\AppData\\Local\\Temp/ipykernel_8188/2215183871.py\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m      1\u001b[0m \u001b[1;31m# in 可以查询数据是否存在\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 2\u001b[1;33m \u001b[1;34m\"Jack\"\u001b[0m \u001b[1;32min\u001b[0m \u001b[0m网三_name_list\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[1;31mNameError\u001b[0m: name '网三_name_list' is not defined"
     ]
    }
   ],
   "source": [
    "# in 可以查询数据是否存在\n",
    "\"Jack\" in 网三_name_list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "4eaca11d",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 关于运算法则 (in + 切片 取值 len(s) s.count)\n",
    "网三_name_list_转专业 = [\"Xiaoming\",\"Lihua\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "492eb227",
   "metadata": {},
   "outputs": [],
   "source": [
    "网三_name_list_转专业 = [\"Xiaoming\",\"Lihua\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0685531d",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "id": "cad711c8",
   "metadata": {},
   "source": [
    "# 2.2列表的方法（Function）--对列表数据进行操作\n",
    "> 1. 增\n",
    "> 2. 删\n",
    "> 3. 改\n",
    "> 4. 查"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "aa348f08",
   "metadata": {},
   "outputs": [],
   "source": [
    "网三_name_list = [\"Marry\",\"Alex\",\"Jack\",\"周晓明\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "bc706333",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Marry', 'Alex', 'Jack', '周晓明']"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "网三_name_list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "id": "2f55c489",
   "metadata": {},
   "outputs": [],
   "source": [
    "网三_name_list.append(\"张志豪\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "id": "c21a553e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Marry', 'Alex', 'Jack', '周晓明', '张志豪']"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "网三_name_list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "id": "dea4871e",
   "metadata": {},
   "outputs": [],
   "source": [
    "网三_name_list.append(\"王一鸣\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "id": "0a9a7203",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Marry', 'Alex', 'Jack', '周晓明', '张志豪', '王一鸣']"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "网三_name_list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d3fc48e3",
   "metadata": {},
   "outputs": [],
   "source": [
    "# insert 增加元素到某个位置"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "id": "2c3cf50b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function insert:\n",
      "\n",
      "insert(index, object, /) method of builtins.list instance\n",
      "    Insert object before index.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(网三_name_list.insert)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "id": "c3aa8c3f",
   "metadata": {},
   "outputs": [],
   "source": [
    "网三_name_list.insert(1,\"李华\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "id": "bd1d120e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Marry', '李华', 'Alex', 'Jack', '周晓明', '张志豪', '王一鸣']"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "网三_name_list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0881e2ea",
   "metadata": {},
   "outputs": [],
   "source": [
    "#"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "id": "8b784d06",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function remove:\n",
      "\n",
      "remove(value, /) method of builtins.list instance\n",
      "    Remove first occurrence of value.\n",
      "    \n",
      "    Raises ValueError if the value is not present.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(网三_name_list.remove)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "id": "ff78156b",
   "metadata": {},
   "outputs": [],
   "source": [
    "网三_name_list.remove(\"Alex\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "id": "9224c487",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Marry', '李华', 'Jack', '周晓明', '张志豪', '王一鸣']"
      ]
     },
     "execution_count": 42,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "网三_name_list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "id": "50e79abb",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Marry', '李华', 'Jack', '周晓明', '张志豪', '王一鸣']"
      ]
     },
     "execution_count": 43,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# remove 经常和 in 一起使用，先检查成员变量是否存在，然后在remove\n",
    "if \"Alex\" in 网三_name_list:\n",
    "    网三_name_list.remove(\"Alex\")\n",
    "网三_name_list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "id": "b5c935f5",
   "metadata": {},
   "outputs": [],
   "source": [
    "# pop"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "id": "403eb110",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function pop:\n",
      "\n",
      "pop(index=-1, /) method of builtins.list instance\n",
      "    Remove and return item at index (default last).\n",
      "    \n",
      "    Raises IndexError if list is empty or index is out of range.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(网三_name_list.pop)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "id": "e4d58053",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'王一鸣'"
      ]
     },
     "execution_count": 46,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "网三_name_list.pop()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "id": "41b5c664",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Jack'"
      ]
     },
     "execution_count": 48,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "网三_name_list.pop(2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "id": "9212ec73",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Marry', '李华', '周晓明', '张志豪']"
      ]
     },
     "execution_count": 49,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "网三_name_list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "id": "785b7e19",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 实践：请移出19的元素\n",
    "age_list = [18,19,18,19,17,20,20,18,19,16,17,20]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "id": "0c16bb93",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3"
      ]
     },
     "execution_count": 59,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "age_list.count(19)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "id": "3b2a48b5",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[18, 19, 18, 19, 17, 20, 20, 18, 19, 16, 17, 20]"
      ]
     },
     "execution_count": 60,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "age_list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 62,
   "id": "8b561f00",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[18, 18, 17, 20, 20, 18, 16, 17, 20]"
      ]
     },
     "execution_count": 62,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 思路1：\n",
    "删除的数量 = age_list.count(19)\n",
    "for i in range(删除的数量):\n",
    "    if 19 in age_list:\n",
    "        age_list.remove(19)\n",
    "    age_list\n",
    "age_list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 64,
   "id": "69d61bf9",
   "metadata": {},
   "outputs": [],
   "source": [
    "age_list = [18,19,18,19,17,20,20,18,19,16,17,20]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 67,
   "id": "0a2a1d17",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[18, 19, 18, 19, 17, 20, 20, 18, 19, 16, 17, 20]"
      ]
     },
     "execution_count": 67,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "age_list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 69,
   "id": "32498f00",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1 19\n",
      "2 19\n",
      "6 19\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "[18, 18, 17, 20, 20, 18, 16, 17, 20]"
      ]
     },
     "execution_count": 69,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 思路2：pop(index),先决条件，知道值出现的位置\n",
    "for i,v in enumerate(age_list):\n",
    "    if v == 19:\n",
    "        print(i,v)\n",
    "        age_list.pop(i)\n",
    "age_list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7c0199f3",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 课后练习：\n",
    "# 1. 课本P69和P81\n",
    "# 2. 剩下的reserve,extend,clear,copy,sort回去之后尝试联系\n",
    "# 3. 总结列表的方法，用表格的形式写在markdown上面"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "129b056c",
   "metadata": {},
   "outputs": [],
   "source": [
    "phrase = \"Don't panic\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "dd7e69a7",
   "metadata": {},
   "outputs": [],
   "source": [
    "plist = list(phrase)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "e4252200",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Don't panic\n",
      "['D', 'o', 'n', \"'\", 't', ' ', 'p', 'a', 'n', 'i', 'c']\n"
     ]
    }
   ],
   "source": [
    "print(phrase)\n",
    "print(plist)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "09b5bcd5",
   "metadata": {},
   "outputs": [],
   "source": [
    "for i in range(4):\n",
    "        plist.pop()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "3505d06a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'D'"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "plist.pop(0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "id": "d45423ed",
   "metadata": {},
   "outputs": [
    {
     "ename": "ValueError",
     "evalue": "list.remove(x): x not in list",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mValueError\u001b[0m                                Traceback (most recent call last)",
      "\u001b[1;32m~\\AppData\\Local\\Temp/ipykernel_4688/229624214.py\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mplist\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mremove\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"'\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[1;31mValueError\u001b[0m: list.remove(x): x not in list"
     ]
    }
   ],
   "source": [
    "plist.remove(\"'\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "id": "fff9dd7e",
   "metadata": {},
   "outputs": [],
   "source": [
    "plist.extend([plist.pop(),plist.pop()])\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "id": "18680ec3",
   "metadata": {},
   "outputs": [
    {
     "ename": "SyntaxError",
     "evalue": "unexpected EOF while parsing (Temp/ipykernel_4688/174563238.py, line 1)",
     "output_type": "error",
     "traceback": [
      "\u001b[1;36m  File \u001b[1;32m\"C:\\Users\\wxm\\AppData\\Local\\Temp/ipykernel_4688/174563238.py\"\u001b[1;36m, line \u001b[1;32m1\u001b[0m\n\u001b[1;33m    plist.insert(2, plist.pop(3)\u001b[0m\n\u001b[1;37m                                ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m unexpected EOF while parsing\n"
     ]
    }
   ],
   "source": [
    "plist.insert(2, plist.pop(3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "id": "10c18853",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['o', 'n', ' ', 't', 'p', 'a']\n",
      "on tpa\n"
     ]
    }
   ],
   "source": [
    "new_phrase = ''.join(plist)\n",
    "print(plist)\n",
    "print(new_phrase)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "id": "1d4777be",
   "metadata": {},
   "outputs": [],
   "source": [
    "phrase = \"on tap\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "id": "d96ed82e",
   "metadata": {},
   "outputs": [],
   "source": [
    "plist = list(phrase)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "id": "bd038221",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "on tap\n"
     ]
    }
   ],
   "source": [
    "print(phrase)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "id": "9043d2a7",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['o', 'n', ' ', 't', 'a', 'p']\n"
     ]
    }
   ],
   "source": [
    "print(plist)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "id": "78b9f7b0",
   "metadata": {},
   "outputs": [],
   "source": [
    "new_phrase=''.join(plist[1:3])\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "id": "e7947799",
   "metadata": {},
   "outputs": [
    {
     "ename": "IndexError",
     "evalue": "list index out of range",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mIndexError\u001b[0m                                Traceback (most recent call last)",
      "\u001b[1;32m~\\AppData\\Local\\Temp/ipykernel_4688/306759953.py\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mnew_phrase\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mnew_phrase\u001b[0m\u001b[1;33m+\u001b[0m\u001b[1;34m''\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mjoin\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mplist\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m5\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mplist\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m4\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mplist\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m7\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mplist\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m6\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[1;31mIndexError\u001b[0m: list index out of range"
     ]
    }
   ],
   "source": [
    "new_phrase=new_phrase+''.join([plist[5],plist[4],plist[7],plist[6]])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "id": "b2922bcb",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['o', 'n', ' ', 't', 'a', 'p']\n",
      "n \n"
     ]
    }
   ],
   "source": [
    "print(plist)\n",
    "print(new_phrase)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "29f552b1",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
